<?php

/* Allows a different number of posts to be displayed within each context */

require_once 'classes/LightPressPlugin.php';

class PostsDisplayed extends LightPressPlugin {

    var $constructor_args = array();    // filled in by constructor
    var $default_context = LP_CONTEXT_ALL;
    var $description = 'Controls the number of posts displayed in each context';
    
    var $active = true;
    var $hooks = array();   // only needs constructor to run
    
    var $default_displayed = 10;
    
    function PostsDisplayed(&$frontend, $args, $dummy_run=false) {
        
        // set up class variables and constructor entries for all contexts
        $all_contexts = explode(' ', LP_CONTEXTS);
        foreach($all_contexts as $context) {
            if (($context == 'post') || ($context == 'static'))     // contexts to exclude
                continue;
            $varname = 'display_' . $context;   
            $this->constructor_args[$varname] = 'Number of posts to display for ' . $context;
            $this->$varname = $this->default_displayed;     // set default
        }
        $this->LightPressPlugin($frontend, $args, $dummy_run);
        
        // change count for current context (and record count if using WP-style paging)
        if (!$dummy_run) {
            $context = 'display_' . ($frontend->context['type'] ? $frontend->context['type'] : 'index'); 
            if (isset($this->$context)) {
                $display = $this->$context;
                $c_index =& $frontend->context['index'];
                $frontend->options['posts_per_page'] = $display;
                if (($c_index > 0) && isset($_REQUEST['paged']) && !empty($_REQUEST['paged']))
                    $c_index = (int)$_REQUEST['paged'] * (int)$display;
            }
        }
    }
   
    function hide() {
        return;     // do nothing
    }
    
    function run($hook, &$hook_data) {
        return;     // do nothing
    }
 
}

?>